
********* Event:  Collapsed - No controls. 2 year averages  *************

capt drop _est_*

preserve

forvalues i=70(-1)1 {
gen TimeRelPPR_m`i'=0
replace TimeRelPPR_m`i'=1 if policy_time_index==-`i'
}

forvalues i=1(1)60 {
gen TimeRelPPR_p`i'=0
replace TimeRelPPR_p`i'=1 if policy_time_index==`i'
}
***

*** Minus: 2 year averages
forvalues i=2(2)70 {
gen TimeRelPPR_ym`i'=0
}
local min = 1
local max = 2
forvalues j=2(2)70 {
forvalues i=`min'(1)`max' {
replace TimeRelPPR_ym`j'=1 if TimeRelPPR_m`i'==1
}
local j = `j' + 2
local min = `min' +2
local max = `max' +2
}
****

*** Positive: 2 year averages
forvalues i=2(2)60 {
gen TimeRelPPR_yp`i'=0
}
local min = 1
local max = 2
forvalues j=2(2)60 {
forvalues i=`min'(1)`max' {
replace TimeRelPPR_yp`j'=1 if TimeRelPPR_p`i'==1
}
local j = `j' + 2
local min = `min' +2
local max = `max' +2
}
****

xtset id_eez_tax iyear
reghdfe collapsed TimeRelPPR_ym*  TimeRelPPR_yp*  ///
, absorb( i.id_eez_tax i.iyear )  cluster($ClusterLevel) 
eststo results
parmest, label list(parm label estimate min* max* p) saving(results, replace)

use results, clear
gen stuff_present =  strpos(parm, "TimeRelPPR_") > 0
drop if stuff_present==0
drop dof  label
gen helpvar=_n
gen length=length(parm)
gen time_str = substr(parm,14,1)  if length==14 
replace time_str = substr(parm,14,2)  if length==15
drop if p==.
destring time_str , generate(time_num)

gen minus=0
replace minus=1 if strpos(parm, "ym")
replace time_num=time_num*-1 if minus==1 
sort time_num

label variable estimate "DiD estimate"
label variable min95 "lower 95% CI "
label variable max95 " upper 95% CI"

sum time_num
summarize helpvar
local max=r(max)
expand 2 if helpvar==`max'
gen helpvar2=_n
summarize helpvar2
local max=r(max)
replace estimate=0 if helpvar2==`max'
replace min95=0 if helpvar2==`max'
replace max95=0 if helpvar2==`max'
replace time_num=0 if helpvar2==`max'

drop if  time_num<-$TimeMin | time_num>$TimeMax

twoway ///
(rarea min95 max95 time_num , sort color(gs13)) ///
(connected  estimate time_num , sort mcolor(blue) lpattern(solid) lcolor(blue)   msymbol(o)     ) ///
, yline(0) xline(0 , lpattern(dash) ) ///
scheme(s2mono) graphregion(fcolor(white) lcolor(white)ifcolor(white) ilcolor(white))  ///
legend(on order( 1 "95% CI" 2 "DiD estimate" )) ///
xtitle(Years relative to implementation) ytitle(Effect of PPR) ///
ylab( -0.4(0.2)0.4  )  xlabel(-$TimeMin (10) $TimeMax )  scale(1.3)
graph export "${figures}\Event_Collapse_2y_NoControls.${fileformat}", as(${fileformat}) /*preview(on)*/ replace
*** MAIN
restore





********* Event:  Collapsed - Long controls. 2 year averages  *************
preserve

forvalues i=60(-1)1 {
gen TimeRelPPR_m`i'=0
replace TimeRelPPR_m`i'=1 if policy_time_index==-`i'
}

forvalues i=1(1)60 {
gen TimeRelPPR_p`i'=0
replace TimeRelPPR_p`i'=1 if policy_time_index==`i'
}
***

*** Minus: 2 year averages
forvalues i=2(2)60 {
gen TimeRelPPR_ym`i'=0
}
local min = 1
local max = 2
forvalues j=2(2)60 {
forvalues i=`min'(1)`max' {
replace TimeRelPPR_ym`j'=1 if TimeRelPPR_m`i'==1
}
local j = `j' + 2
local min = `min' +2
local max = `max' +2
}
****

*** Positive: 2 year averages
forvalues i=2(2)60 {
gen TimeRelPPR_yp`i'=0
}
local min = 1
local max = 2
forvalues j=2(2)60 {
forvalues i=`min'(1)`max' {
replace TimeRelPPR_yp`j'=1 if TimeRelPPR_p`i'==1
}
local j = `j' + 2
local min = `min' +2
local max = `max' +2
}
****

xtset id_eez_tax iyear
reghdfe collapsed TimeRelPPR_ym*  TimeRelPPR_yp*  ///
$ControlsLong ///
, absorb( i.id_eez_tax i.iyear )  cluster($ClusterLevel) 
eststo results
parmest, label list(parm label estimate min* max* p) saving(results, replace)
restore

preserve
use results, clear
gen stuff_present =  strpos(parm, "TimeRelPPR_") > 0
drop if stuff_present==0
drop dof  label
gen helpvar=_n
gen length=length(parm)
gen time_str = substr(parm,14,1)  if length==14 
replace time_str = substr(parm,14,2)  if length==15
drop if p==.
destring time_str , generate(time_num)

gen minus=0
replace minus=1 if strpos(parm, "ym")
replace time_num=time_num*-1 if minus==1 
sort time_num

label variable estimate "DiD estimate"
label variable min95 "lower 95% CI "
label variable max95 " upper 95% CI"

sum time_num
summarize helpvar
local max=r(max)
expand 2 if helpvar==`max'
gen helpvar2=_n
summarize helpvar2
local max=r(max)
replace estimate=0 if helpvar2==`max'
replace min95=0 if helpvar2==`max'
replace max95=0 if helpvar2==`max'
replace time_num=0 if helpvar2==`max'

drop if  time_num<-$TimeMin | time_num>$TimeMax

twoway ///
(rarea min95 max95 time_num , sort color(gs13)) ///
(connected  estimate time_num , sort mcolor(blue) lpattern(solid) lcolor(blue)   msymbol(o)     ) ///
, yline(0) xline(0 , lpattern(dash) ) ///
scheme(s2mono) graphregion(fcolor(white) lcolor(white)ifcolor(white) ///
ilcolor(white))  legend(on order( 1 "95% CI" 2 "DiD estimate" )) ///
xtitle(Years relative to implementation) ytitle(Effect of PPR) ///
ylab( -0.4(0.2)0.4  )  xlabel(-$TimeMin (10) $TimeMax )  scale(1.3)
graph export "${figures}\Event_Collapse_2y_ControlsLong.${fileformat}", as(${fileformat}) /*preview(on)*/ replace
** MAIN

restore
**************



********* Event:  IntoCollapse - No Controls. 2 year averages  *************
preserve

forvalues i=60(-1)1 {
gen TimeRelPPR_m`i'=0
replace TimeRelPPR_m`i'=1 if policy_time_index==-`i'
}

forvalues i=1(1)60 {
gen TimeRelPPR_p`i'=0
replace TimeRelPPR_p`i'=1 if policy_time_index==`i'
}
***


*** Minus: 2 year averages
forvalues i=2(2)60 {
gen TimeRelPPR_ym`i'=0
}
local min = 1
local max = 2
forvalues j=2(2)60 {
forvalues i=`min'(1)`max' {
replace TimeRelPPR_ym`j'=1 if TimeRelPPR_m`i'==1
}
local j = `j' + 2
local min = `min' +2
local max = `max' +2
}
****

*** Positive: 5 year averages
forvalues i=2(2)60 {
gen TimeRelPPR_yp`i'=0
}
local min = 1
local max = 2
forvalues j=2(2)60 {
forvalues i=`min'(1)`max' {
replace TimeRelPPR_yp`j'=1 if TimeRelPPR_p`i'==1
}
local j = `j' + 2
local min = `min' +2
local max = `max' +2
}
****

xtset id_eez_tax iyear
reghdfe IntoCollapse TimeRelPPR_ym*  TimeRelPPR_yp*  ///
, absorb( i.id_eez_tax i.iyear )  cluster($ClusterLevel) 
eststo results
parmest, label list(parm label estimate min* max* p) saving(results, replace)

use results, clear
gen stuff_present =  strpos(parm, "TimeRelPPR_") > 0
drop if stuff_present==0
drop dof  label
gen helpvar=_n
gen length=length(parm)
gen time_str = substr(parm,14,1)  if length==14 
replace time_str = substr(parm,14,2)  if length==15
drop if p==.
destring time_str , generate(time_num)

gen minus=0
replace minus=1 if strpos(parm, "ym")
replace time_num=time_num*-1 if minus==1 
sort time_num

label variable estimate "DiD estimate"
label variable min95 "lower 95% CI "
label variable max95 " upper 95% CI"

sum time_num
summarize helpvar
local max=r(max)
expand 2 if helpvar==`max'
gen helpvar2=_n
summarize helpvar2
local max=r(max)
replace estimate=0 if helpvar2==`max'
replace min95=0 if helpvar2==`max'
replace max95=0 if helpvar2==`max'
replace time_num=0 if helpvar2==`max'

drop if  time_num<-$TimeMin | time_num>$TimeMax

twoway ///
(rarea min95 max95 time_num , sort color(gs13)) ///
(connected  estimate time_num , sort mcolor(blue) lpattern(solid) lcolor(blue)   msymbol(o)     ) ///
, yline(0) xline(0 , lpattern(dash) ) ///
scheme(s2mono) graphregion(fcolor(white) lcolor(white)ifcolor(white) ///
ilcolor(white))  legend(on order( 1 "95% CI" 2 "DiD estimate" )) ///
xtitle(Years relative to implementation) ytitle(Effect of PPR) ///
ylab( -0.08(0.04)0.08  )  xlabel(-$TimeMin (10) $TimeMax )  scale(1.3)
graph export "${figures}\Event_IntoCollapse_2y_NoControls.${fileformat}", as(${fileformat}) /*preview(on)*/ replace
** MAIN
restore
**************



********* Event:  IntoCollapse - controls long. 2 year averages  *************
preserve

forvalues i=60(-1)1 {
gen TimeRelPPR_m`i'=0
replace TimeRelPPR_m`i'=1 if policy_time_index==-`i'
}

forvalues i=1(1)60 {
gen TimeRelPPR_p`i'=0
replace TimeRelPPR_p`i'=1 if policy_time_index==`i'
}
***


*** Minus: 2 year averages
forvalues i=2(2)60 {
gen TimeRelPPR_ym`i'=0
}
local min = 1
local max = 2
forvalues j=2(2)60 {
forvalues i=`min'(1)`max' {
replace TimeRelPPR_ym`j'=1 if TimeRelPPR_m`i'==1
}
local j = `j' + 2
local min = `min' +2
local max = `max' +2
}
****

*** Positive: 2 year averages
forvalues i=2(2)60 {
gen TimeRelPPR_yp`i'=0
}
local min = 1
local max = 2
forvalues j=2(2)60 {
forvalues i=`min'(1)`max' {
replace TimeRelPPR_yp`j'=1 if TimeRelPPR_p`i'==1
}
local j = `j' + 2
local min = `min' +2
local max = `max' +2
}
****

xtset id_eez_tax iyear
reghdfe IntoCollapse TimeRelPPR_ym*  TimeRelPPR_yp*  ///
$ControlsLong ///
, absorb( i.id_eez_tax i.iyear )  cluster($ClusterLevel) 
eststo results
parmest, label list(parm label estimate min* max* p) saving(results, replace)

use results, clear
gen stuff_present =  strpos(parm, "TimeRelPPR_") > 0
drop if stuff_present==0
drop dof  label
gen helpvar=_n
gen length=length(parm)
gen time_str = substr(parm,14,1)  if length==14 
replace time_str = substr(parm,14,2)  if length==15
drop if p==.
destring time_str , generate(time_num)

gen minus=0
replace minus=1 if strpos(parm, "ym")
replace time_num=time_num*-1 if minus==1 
sort time_num

label variable estimate "DiD estimate"
label variable min95 "lower 95% CI "
label variable max95 " upper 95% CI"

sum time_num
summarize helpvar
local max=r(max)
expand 2 if helpvar==`max'
gen helpvar2=_n
summarize helpvar2
local max=r(max)
replace estimate=0 if helpvar2==`max'
replace min95=0 if helpvar2==`max'
replace max95=0 if helpvar2==`max'
replace time_num=0 if helpvar2==`max'

drop if  time_num<-$TimeMin | time_num>$TimeMax

twoway ///
(rarea min95 max95 time_num , sort color(gs13)) ///
(connected  estimate time_num , sort mcolor(blue) lpattern(solid) lcolor(blue)   msymbol(o)     ) ///
, yline(0) xline(0 , lpattern(dash) ) ///
scheme(s2mono) graphregion(fcolor(white) lcolor(white)ifcolor(white) ///
ilcolor(white))  legend(on order( 1 "95% CI" 2 "DiD estimate" )) ///
xtitle(Years relative to implementation) ytitle(Effect of PPR) ///
ylab( -0.08(0.04)0.08  )  xlabel(-$TimeMin (10) $TimeMax )  scale(1.3)
graph export "${figures}\Event_IntoCollapse_2y_ControlsLong.${fileformat}", as(${fileformat}) /*preview(on)*/ replace
** MAIN


restore
**************

capt drop _est_*

